<template>
    <el-submenu v-if="item.children && item.children.length>=1 && ((item.role && role===item.role) || !item.role)" :index="navIndex">
      <!--创建父级菜单 -->
      <template slot="title">
        <i :class="item.icon"></i>
        <span slot="title">{{item.name}}</span>
      </template>
      <!--创建子级菜单 -->
      <nav-item v-for="(subItem,i) in item.children" :item="subItem" :navIndex="navIndex + '-' + i" :key="navIndex + '-' + i"></nav-item>
    </el-submenu>
  <el-menu-item v-else-if="item.children && item.children.length==1 && ((item.role && role===item.role) || !item.role)" :index="item.children[0].path"
    @click='groupActive(item.children[0].path,item.children[0].name)'>
    <i :class="item.children[0].icon"></i>
    <span>{{ item.children[0].name }}</span>
  </el-menu-item>
  <el-menu-item v-else-if="!item.children && ((item.role && role===item.role) || !item.role)" :index="item.path" @click='groupActive(item.path,item.name)'>
    <span>{{ item.name }}</span>
  </el-menu-item>
</template>

<script>
  import {
    get,
    post,
    common,
    getRefresh
  } from "../../../api/api";

  export default {
    //递归组件必须要有name,props接收传递过来的参数
    name: "navItem",
    props: ["item", "navIndex"],
    data() {
      return {
        pathList: []
      };
    },
    methods: {
      groupActive(path, name) {
        // console.log(path, name);
        // if (name == "分组管理") {
        //   get("/auth/auto-login").then(resdata => {
        //     console.log(resdata);
        //     if (resdata.code == 2) {
        //       get("/auth/refresh").then(data => {
        //         if (data.code != 0) {
        //           localStorage.removeItem("token");
        //           then[1].push({
        //             path: "/home"
        //           });
        //         } else {
        //           localStorage.setItem("token", data.data.token);
        //           this.groupActive(path, name);
        //         }
        //       });
        //     } else {
        //       sessionStorage.setItem("userGroup", resdata.data.group);
        //       sessionStorage.setItem("type", 0);
        //       sessionStorage.setItem("breadcrumbName", JSON.stringify([]));
        //       sessionStorage.setItem("oldPath", JSON.stringify([]));
        //     }
        //   });
        // }
      }
    }
  };

</script>


<style>


</style>
